import random
times = 0
list1 = []
n = 0
name = input('Input your name:')
while True:
    a = random.randint(1,100)
    times += 1
    total =0
    while True:
        try:
            num = int(input('Guess a number(1-100):'))
            total += 1
            n+=1
            if num > a:
                print('Too big, please try again.')
            elif num < a:
                print('Too small, please try again.')
            else:
                print('Bingo!')
                list1.append(total)
                ave_time = n / times
                least = min(list1)
                print('谢谢！你一共玩了%d次游戏, 一共猜了%d轮,平均%.2f轮猜出, 最少%d轮猜出答案.' % (times, n, ave_time,least))
                result = '%s %d %d %d' % (name, times, n, least)
                break
        except ValueError:
            print('请输入数字！')
            continue
    i = input('Continue(Y/N):')
    if i.lower() != 'y':


        break

with open('game_one_user.txt','a') as f:
    f.write(result)